package brc.syntacticTree;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

public class CodeBlockNode implements TreeNode {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2197405583391147610L;
	private List<TreeNode> nodes;
	
	public CodeBlockNode(List<TreeNode> nodes) {
		if (nodes == null) {
			throw new NullPointerException("You must specify the nodes of the code block");
		}
		this.nodes = nodes;
	}
	
	public List<TreeNode> getNodes() {
		return nodes;
	}

	@Override
	public void writeAssembly(Writer writer) throws IOException {
		for (TreeNode node : this.nodes) {
			node.writeAssembly(writer);
		}
	}

	@Override
	public void semanticCheck() throws SemanticException {
		for (TreeNode node : this.nodes) {
			try {
				node.semanticCheck();
			}
			catch (SemanticException ex) {
				// write semantic error here
				ex.printStackTrace();
			}
		}
	}
}
